package com.wokeMy.view.adpter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wokeMy.view.DetailDhActivity;
import com.wokeMy.view.model.GhtZd;
import com.wokeMy.view.util.Util;
import com.zhongcai.online.R;

import java.util.ArrayList;


/**
 * Created by Administrator on 2017-11-22.
 */

public class RecordDhAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    ArrayList<GhtZd> ghtList=new ArrayList<>() ;
    Context context;
    int way_id;
    public RecordDhAdapter(Context context,ArrayList<GhtZd> ghtList,int way_id) {
        this.inflater = LayoutInflater.from(context);
        this.ghtList=ghtList;
        this.context=context;
        this.way_id=way_id;
    }

    @Override
    public int getCount() {
        return ghtList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold viewHold;
        if (convertView==null){
            viewHold=new ViewHold();
            convertView=inflater.inflate(R.layout.item_rc_lv,null);
            viewHold.tvTitle=(TextView)convertView.findViewById(R.id.rc_titlle);
            viewHold.tvTime=(TextView)convertView.findViewById(R.id.rc_time);
            viewHold.tvState=(TextView)convertView.findViewById(R.id.rc_state);
            convertView.setTag(viewHold);
        }else {
            viewHold=(ViewHold)convertView.getTag();
        }
        final GhtZd ghtZd = ghtList.get(position);
        //type;//0信用卡 1储蓄卡
        //00 成功到账  03支付中 04支付成功 05支付失败 99到账失败
        if(ghtZd.getType().equals("0")){
            viewHold.tvTitle.setText("代还 ("+ Util.twoString(ghtZd.getAmount())+")");
            }else{
            viewHold.tvTitle.setText("快捷 ("+ Util.twoString(ghtZd.getAmount())+")");
         }
         String tip;
        switch (ghtZd.getStatus()) {
            case "00":
                tip="成功到账";
                break;
            case "03":
                tip="支付中";
                break;
            case "04":
                tip="支付成功";
                break;
            case "05":
                tip="支付失败";
                break;
            case "99":
                tip="到账失败";
                break;
            default:
                tip="到账失败";
                break;
        }
        viewHold.tvState.setText(tip);
        viewHold.tvTime.setText(Util.getStrTi(ghtZd.getCreate_time()));
        Log.e("getView",way_id+"");
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent inte1 = new Intent (context, DetailDhActivity.class);
                inte1.putExtra("detail",ghtZd);
                inte1.putExtra ("way_id",way_id);
                context.startActivity(inte1);
            }
        });
        return convertView;
    }
    class ViewHold{
        TextView tvTitle;
        TextView tvTime;
        TextView tvState;
    }
}
